<html>
<head>

<title>Groovy Goodness: Powerful Assert</title>

<script language="javascript" src="scripts/shCore.js"></script> 
<script language="javascript" src="scripts/shLegacy.js"></script> 
<script language="javascript" src="scripts/shBrushJava.js"></script> 
<script language="javascript" src="scripts/shBrushXml.js"></script> 
<script language="javascript" src="scripts/shBrushJScript.js"></script> 
<script language="javascript" src="scripts/shBrushGroovy.js"></script> 
<script language="javascript" src="scripts/shBrushPlain.js"></script> 
<script language="javascript" src="scripts/shBrushBash.js"></script> 
 
<link href="styles/reset.css" rel="stylesheet" type="text/css" />
<link href="styles/shCore.css" rel="stylesheet" type="text/css" />
<link type="text/css" rel="stylesheet" href="styles/shThemeRDark.css"/>
<link href="styles/blog.css" rel="stylesheet" type="text/css" />

</head>
<body>

<a href="index.html">Back to index</a>

<h3 class="post-title">Groovy Goodness: Powerful Assert</h3>

<div class="post">
<p>In Groovy 1.7 we get a lot of information if an assertion isn't true. Before we only could see the assertion was false, but now we get a breakdown of all components used in the assertion. For each component the return value is shown, so we can easily determine what component is responsible for the false assertion.</p>
<p>For example we run the following code:</p>
<pre class="brush:groovy">
def list = [1, 2, 3, 4, 5]
assert 4 == list.max() - 2
</pre>
<p>And the assert output is:</p>
<pre class="brush:plain;light:true">
assert 4 == list.max() - 2
         |  |    |     |
         |  |    5     3
         |  [1, 2, 3, 4, 5]
         false
</pre>
<p>We notice how the output shows the contents of the list, the output of <code>list.max()</code> and the result of <code>list.max() - 2</code>.</p
</div>

<script language="javascript"> 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = 'scripts/clipboard.swf';
SyntaxHighlighter.defaults['first-line'] = 0;
SyntaxHighlighter.defaults['auto-links'] = false;
SyntaxHighlighter.all();
dp.SyntaxHighlighter.HighlightAll('code');
</script>

</body>
</html>